<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    tbody {
      background: yellow;
      height: 100px;
      width: 100%;
    }

    .box {
      margin-left: 80px;
      height: 30px;
      line-height: 30px;
    }

    table {
      width: 1200px;
      margin: 0 auto;
      border: 1px solid red;
      border-collapse: collapse;
    }

    table tr,
    table td {
      border: 1px solid red;
    }

    tr {
      height: 30px;
    }
  </style>
</head>

<body>
  <div class="box">
    <label for="row">行：</label><input type="text" id="row" value="">
    <label for="column">列：</label><input type="text" id="column" value="">
    <input class="btn" type="button" value="生成表格">
  </div>
  <table>
    <tbody>
      <!-- <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
      </tr> -->
    </tbody>

  </table>

  <script>
    // 6、生成任意表格

    let row = document.getElementById('row'); //行
    let column = document.getElementById("column"); //列
    let btn = document.querySelector(".btn"); //生成按钮
    let tbody = document.querySelector("tbody");


    btn.addEventListener("click", function () {
      let rowValue = row.value; //获取到行表单的值
      let columnValue = column.value; //获取到列表单的值

      tbody.innerHTML = "" //对tbody置空
      for (let i = 0; i < rowValue; i++) { //行
        let tr = document.createElement('tr') //01：创建行
        // tr.innerHTML = ` 
        //     <td>1</td>
        //     <td>2</td>
        //     <td>3</td>
        // `
        tbody.appendChild(tr); //添加行
        for (let j = 0; j < columnValue; j++) { //列
          let td = document.createElement('td'); //创建列
          tr.appendChild(td); //添加列
        }
      }
    })
  </script>
</body>

</html>